package com.pointstar.dp.modules.project.service.impl;

import com.pointstar.dp.common.entity.Page;
import com.pointstar.dp.common.entity.Query;
import com.pointstar.dp.common.entity.R;
import com.pointstar.dp.common.utils.CommonUtils;
import com.pointstar.dp.modules.project.dao.ProjectRecordMapper;
import com.pointstar.dp.modules.project.entity.ProjectRecordEntity;
import com.pointstar.dp.modules.project.service.ProjectRecordService;
import com.pointstar.dp.modules.project.util.EntityUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * 项目记录表
 * @author zhukerui
 */
@Service("projectRecordService")
public class ProjectRecordServiceImpl implements ProjectRecordService {

	private final ProjectRecordMapper projectRecordMapper;

    @Autowired
    public ProjectRecordServiceImpl(ProjectRecordMapper projectRecordMapper) {
        this.projectRecordMapper = projectRecordMapper;
    }

    /**
     * 分页查询
     * @param params
     * @return
     */
	@Override
	public Page<ProjectRecordEntity> listProjectRecord(Map<String, Object> params) {
		Query query = new Query(params);
		Page<ProjectRecordEntity> page = new Page<>(query);
		projectRecordMapper.listForPage(page, query);
		return page;
	}

    /**
     * 新增
     * @param projectRecord
     * @return
     */
	@Override
	public R saveProjectRecord(ProjectRecordEntity projectRecord) {
        int count = projectRecordMapper.save((ProjectRecordEntity) EntityUtil.convertEntity(projectRecord));
		return CommonUtils.msg(count);
	}

    /**
     * 根据id查询
     * @param id
     * @return
     */
	@Override
	public R getProjectRecordById(Long id) {
		ProjectRecordEntity projectRecord = projectRecordMapper.getObjectById(id);
		return CommonUtils.msg(projectRecord);
	}

    /**
     * 修改
     * @param projectRecord
     * @return
     */
	@Override
	public R updateProjectRecord(ProjectRecordEntity projectRecord) {
		int count = projectRecordMapper.update((ProjectRecordEntity) EntityUtil.convertEntity(projectRecord));
		return CommonUtils.msg(count);
	}

    /**
     * 删除
     * @param id
     * @return
     */
	@Override
	public R batchRemove(Long[] id) {
		int count = projectRecordMapper.batchRemove(id);
		return CommonUtils.msg(id, count);
	}
}
